import sys

from PyQt6.QtCore import QDate, Qt, QBasicTimer
from PyQt6.QtWidgets import QCalendarWidget, QLabel, QWidget, QApplication, QSlider, QVBoxLayout, QProgressBar


class calendar_init(QWidget):
    def __init__(self):
        super().__init__()
        self.setGeometry(300, 300, 300, 240)
        self.setWindowTitle('Calendar Initializer')
        self.initUI()

    pvalue = 0
    def initUI(self):
        self.slider = QSlider(Qt.Orientation.Horizontal, self)
        self.slider.setMinimum(0)
        self.slider.setMaximum(100)
        self.slider.setSingleStep(2)
        self.slider.setValue(0)
        self.slider.setTickPosition(QSlider.TickPosition.TicksBelow)
        vbox = QVBoxLayout()
        vbox.addWidget(self.slider)
        self.setLayout(vbox)

        self.slider.setTickInterval(10)

        self.slider.valueChanged.connect(self.valueFunc)


        self.pgb = QProgressBar(self)
        self.pgb.setRange(0, 100)
        self.pgb.setValue(self.pvalue)

        self.setPgdValue()

        self.cal = QCalendarWidget(self)
        self.cal.setMinimumDate(QDate(2000,1,1))
        self.cal.setMaximumDate(QDate(2100,1,31))
        self.cal.setGridVisible(True)
        self.cal.move(10,10)


        self.cal.clicked.connect(self.labShow)

        date = self.cal.selectedDate()
        self.lb = QLabel(self)
        self.lb.setText(f"Select Date :{date.toString('yyyy-MM-dd')}")

        vbox.addWidget(self.cal)
        vbox.addWidget(self.lb)
        vbox.addWidget(self.pgb)

    def setPgdValue(self):
        self.timer = QBasicTimer()
        self.timer.start(100, self)

    def timerEvent(self, e):
        if self.pvalue == 100:
            self.timer.stop()
            self.pgb.setValue(self.pvalue)
        else:
            self.pvalue += 1
            self.pgb.setValue(self.pvalue)

    def labShow(self):
        self.lb.setText(self.cal.selectedDate().toString('yyyy-MM-dd'))

    def valueFunc(self):
        print(f"value {self.slider.value()}")

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = calendar_init()
    window.show()
    sys.exit(app.exec())
